package dao;

import entity.User;

public class UserDao {
    public User login(String sql,String userName,String password){
        User user=null;
        try {
            user = jdbc2.selectOne(User.class,sql,userName,password);
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return user;
    }

    public static int registry(String sql,String userName,String password){
        // connection:保证事务中的sql都在同一个请求连接中
        // 该方法的返回值时insert语句执行完毕后，数据生成的该数据id
        return jdbc2.doInsert(jdbc2.connection,sql,userName,password);
    }
    // 查询用户要注册的账号是否重复
    public User getUserByUserName(String sql,String userName){
        User user=null;
        try {
            user= jdbc2.selectOne(User.class,sql,userName);
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return user;
    }


}
